<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text">
    <script>
        const input = document.querySelector('input')
        const sendMsg = function (...args) {
            console.log(args.reduce((prev, el) => {
                return prev + el
            }, 0))
        }
        const debounce = (fn, ms) => {
            let timerId
            return function (...args) { // 剩余参数
                clearInterval(timerId)
                timerId = setTimeout(() => {
                    // fn.call(this, ...args) // 扩展运算符
                    // args是真数组，apply接收数组，call接收参数序列
                    fn.apply(this, args)
                }, ms)
            }
        }
        // input.addEventListener('keyup', sendMsg.bind(input, 1, 2))
        input.addEventListener('keyup', debounce(sendMsg, 500).bind(input, 1, 2, 3, 4))
    </script>
</body>

</html>